#ifndef __SURFACE_RENDERER__
#define __SURFACE_RENDERER__

#include "primitiverenderer.h"
#include "surface.h"

class SurfaceRenderer : public PrimitiveRenderer {
public:
	SurfaceRenderer(Surface* primitive, size_t samplesPatch = 3, const Vec2n& urange = math::V2n(0.0, 1.0), const Vec2n& vrange = math::V2n(0.0, 1.0), Vec3n color = math::V3n(1.0, 1.0, 1.0), bool renderControlPolygon = true, bool renderIsoCurves = true);
	virtual ~SurfaceRenderer();
	virtual void Init();
	virtual void Render() const;
	virtual void Update();
	void RenderGL() const;
	void RenderWireframeGL() const;
	void RenderControlpolygonGL() const;
private:
	typedef boost::tuples::tuple< Vec3n, Vec3n, Vec2n > Vertex;
	typedef boost::multi_array<Vertex, 2> VertexArray;
	void InitSurface(const std::vector<nfloat>& A, const std::vector<nfloat>& B);
	void RenderQuadBack(const Vertex& V1, const Vertex& V2, const Vertex& V3, const Vertex& V4, bool ccw, bool flag1 = true, bool flag2 = true) const;
	void RenderSurface(size_t samplesPatch, bool flag = true) const;

	VertexArray surface;
	
	Vec2n urange, vrange;
	size_t numisocurvesU, numisocurvesV;
	size_t samplesPatch;

	GLint list;
	GLint listWireframe;
	GLint listControlPolygon;
	Vec3n color;
	bool renderControlPolygon, renderIsoCurves;
};

#endif //__SURFACE_RENDERER__
